package g2.routemaster.bundle.gui;

import g2.routemaster.gui.ApplicationStart;
import g2.routemaster.model.ModelAdaptor;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;

public class GuiAdaptorActivator implements BundleActivator {
	private ServiceTracker finderTracker;

	private ServiceRegistration listerReg;

	public void start(BundleContext context) throws Exception {
		// Create and open the MovieFinder ServiceTracker
		finderTracker = new ServiceTracker(context, ModelAdaptor.class
				.getName(), null);
		finderTracker.open();

		// Create the MovieLister and register as a service
		GuiAdaptor lister = new GuiAdaptorImpl(finderTracker);
		listerReg = context.registerService(GuiAdaptor.class.getName(), lister,
				null);

		ApplicationStart as = new ApplicationStart(lister); 
		as.run();
	}

	public void stop(BundleContext context) throws Exception {
		// Unregister the MovieLister service
		listerReg.unregister();

		// Close the MovieFinder ServiceTracker
		finderTracker.close();
	}

	/*private void doSample(GuiAdaptor lister) {
		String text = lister.getGreeting();
		if (text == null) {
			System.out.println("problem");
		} else {
			System.out.println(text);
		}
	}*/	
}
